const {Controller}=require("egg")

const {createId}=require("../utils/utils")

class setAdviewsController extends Controller{

    // 获取;
    async getAdviews(){
        const {ctx}=this
        const {type_id}=ctx.request.body
        const result=await ctx.service.setAdviews.getAdviews(type_id)
        if(result.length){
            ctx.body={
                code:"1001",
                msg:"获取数据成功",
                result
            }
        }else{
            ctx.body={
                code:"1002",
                msg:"获取数据失败"
            }
        }
    }

    // 增加  设置
    async create(){
        const {ctx}=this
        const {type_id,views_id}=ctx.request.body
        const id=createId(type_id)
        const result=await ctx.service.setAdviews.create(id,type_id,views_id)
        if(result.affectedRows){
            ctx.body={
                code:"1001",
                msg:"设置视图权限增加成功"
            }
        }else{
            ctx.body={
                code:"1002",
                msg:"设置视图权限增加失败"
            }
        }
    }
}

module.exports=setAdviewsController